package home.diy.UI;

import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import home.diy.R;
import home.diy.Server;

public class Mydialog extends DialogFragment {

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_TITLE, 0);
    }

	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v =inflater.inflate(R.layout.preference_layout, container, false);
        
        Button button = (Button)v.findViewById(R.id.valid_param_button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
        		FragmentTransaction ft = getFragmentManager().beginTransaction();
        		Fragment prev = getFragmentManager().findFragmentByTag("dialog");
        		EditText ip=(EditText)v.findViewById(R.id.ipadress);
        		EditText log=(EditText)v.findViewById(R.id.login);
        		EditText pass=(EditText)v.findViewById(R.id.password);
        		EditText port=(EditText)v.findViewById(R.id.portnumber);
        		int iport=Integer.parseInt(port.getText().toString());
        		Server server=new Server("alpha2", ip.getText().toString(), log.getText().toString(), pass.getText().toString(), iport);
        		
        		if (prev != null) {
        			ft.remove(prev);
        		}
        		ft.addToBackStack(null);
        		ft.commit();
            }
        });

        return v;
    }

}
